package com.zxq.demo.admin.init;

import com.zxq.demo.admin.dao.ZxqJobInfoDao;
import com.zxq.demo.admin.model.ZxqJobInfo;
import com.zxq.demo.admin.thread.TriggerJobThread;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zw
 * @description
 * @email 2408003640@qq.com
 * @date 2025/6/15 21:37
 */
@Component
public class ZxqJobConfig implements InitializingBean {

    private static ZxqJobInfoDao zxqJobInfoDao;
    private static ZxqJobConfig zxqJobConfig;

    public ZxqJobConfig(ZxqJobInfoDao zxqJobInfoDao) {
        ZxqJobConfig.zxqJobInfoDao = zxqJobInfoDao;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        zxqJobConfig = this;
        // 开始定时任务轮询
        new TriggerJobThread().start();
    }

    public static List<ZxqJobInfo> getJobInfoList() {
        return zxqJobInfoDao.list(1);
    }
    public static int updateJobInfo(ZxqJobInfo zxqJobInfo) {
        return zxqJobInfoDao.scheduleUpdate(zxqJobInfo);
    }
}
